package org.huioo.example.springboot001.controller.other;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

/**
 * 结合`@RequestMapping`，设置公共uri前缀
 */
@Controller
@RequestMapping("/other")
public class OtherController {
    private Log log = LogFactory.getLog(this.getClass());

    /**
     * 404 Not Found
     * 没有设置 “other/index.html” 的view
     * @return
     */
    @GetMapping({"/", "/main"})
    public String main(){
        log.info("/other/, /other/main ");
        return "other/index.html";
    }

    /**
     * 指向地址 “http://[ip]:[port]/main”
     * @return
     */
    @GetMapping("/index")
    public String index(){
        log.info("/other/index");
        // 转发到 "/main"
        return "/main";
    }

    /**
     * 内部 view 循环
     *
     * javax.servlet.ServletException: Circular view path [index.html]:
     * would dispatch back to the current handler URL [/other/html/index.html] again.
     * Check your ViewResolver setup!
     * (Hint: This may be the result of an unspecified view, due to default view name generation.)
     * @param htmlName
     * @return
     */
    @GetMapping("/html/{htmlName}")
    public String circleHtml(@PathVariable String htmlName){
        log.info("/other/html/" + htmlName);
        return "html/" + htmlName + ".html";
    }


}
